package com.mjk.mq;


import com.mjk.api.dto.ApiDto;
import com.mjk.common.base.error.BeeError;
import com.mjk.common.base.response.BeeResponse;
import com.mjk.common.base.work.BaseWork;
import com.mjk.common.base.work.annotation.BeeWork;
import com.mjk.common.core.rmq.EventBus;
import com.mjk.common.core.rmq.annotation.Subscribe;
import com.mjk.common.tools.gson.GsonUtils;
import com.mjk.common.tools.logger.BizLogger;

/**
 * RabbitMq 測試用例
 */
@BeeWork(work = "mq")
public class RabbitMqExample extends BaseWork {

    /**
     * 发送MQ信息
     */
    public BeeResponse sendMqInfo(ApiDto dto){
        dto.setA("11");
        EventBus.publish(dto);
        EventBus.p2p(dto);
        EventBus.broadcast(dto);
        return BeeError.BEE_SUC.tranceError();
    }

    @Subscribe
    public void reciverMq(ApiDto dto){
        BizLogger.info(dto);
    }

    @Subscribe(Subscribe.Type.P2P)
    public void reciverMqP2p(ApiDto dto){
        BizLogger.info("p2p"+ GsonUtils.bean2Json(dto));
    }

    @Subscribe(Subscribe.Type.BROADCAST)
    public void reciverMqBroadcast(ApiDto dto){
        BizLogger.info("bradcast" + GsonUtils.bean2Json(dto));
    }
}
